package org.aurora.core.biz.persistence;

import org.apache.ibatis.annotations.*;
import org.aurora.model.entity.Task;

import java.util.List;

@Mapper
public interface TaskMapper {
    String SAVE_BASE_FIELDS = " name, expression, state, appcode, type, description ";
    String QUERY_BASE_FIELDS = " id, " + SAVE_BASE_FIELDS;

    String TABLE_NAME = " task ";

    @Insert("insert into " + TABLE_NAME + " (" + SAVE_BASE_FIELDS + ") values (#{name}, #{expression}, #{state}, #{appcode}, #{type}, #{description}) ")
    @SelectKey(statement = "SELECT LAST_INSERT_ID() AS ID", keyProperty = "id", before = false, resultType = Long.class)
    Long addTask(Task task);

    @Select("select " + QUERY_BASE_FIELDS + " from " + TABLE_NAME + " where id = #{taskId}")
    Task getTask(@Param("taskId") long taskId);

    @Select("select " + QUERY_BASE_FIELDS + " from " + TABLE_NAME + " where appcode = #{appcode}")
    List<Task> queryTasksByAppcode(@Param("appcode") String appcode);

}
